<template>
  <div class="subject">
    <span>{{ number1 }}</span>
    <span>+</span>
    <span>{{ number2 }}</span>
    <span>=</span>
    <input type="number" v-model="key" />
    <button @click="check">提交</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      key: ''
    }
  },
  props: ['number1', 'number2'],
  methods: {
    check() {
      if (+this.key === this.number1 + this.number2) {
        this.$emit('check', 1)
      } else if (this.key === '') {
        this.$emit('check', 2)
      } else {
        this.$emit('check', 3)
      }
    }
  }
}
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>
